package com.codingfuture.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.Serializable;

/**
 * @Author kobe
 * @Date 2021/11/5 14:45
 * @Description
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        System.out.println(session.getId());
        Object username = session.getAttribute("username");
        System.out.println(username);
        if (username != null) {
            return true;
        } else {
            response.sendRedirect("/login.html");
            return false;//放行
        }
    }


}

